//
//  ScoreViewController.m
//  CardWarrior
//
//  Created by Tekka Xie on 12-4-23.
//  Copyright (c) 2012年 Tencent. All rights reserved.
//

#import "ScoreViewController.h"
#import "AudioManager.h"
#import "FontManager.h"
#import "EasyGlyph.h"
#import "GameDataManager.h"

@implementation ScoreViewController

@synthesize starBackgroundA;
@synthesize starBackgroundB;
@synthesize singlePlayer;
@synthesize singlePlayerScore;
@synthesize inviteFriend;
@synthesize inviteFriendScore;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    starBackgroundA.frame = CGRectMake(0, 0, 480, 320);
    starBackgroundB.frame = CGRectMake(0, 320, 480, 320);
    [UIView animateWithDuration: 10.0  delay: 0.0
                        options: UIViewAnimationOptionCurveLinear|UIViewAnimationOptionRepeat
                     animations: ^(){
                         starBackgroundA.frame = CGRectMake(0, -320, 320, 480);
                         starBackgroundB.frame = CGRectMake(0, 0, 480, 320);
                     }
                     completion: nil
     ];
    
    FontManager* pFont = [FontManager sharedInstance];
    [pFont setFontForView:singlePlayer WithSize:17 WithString:@"SINGLE PLAYER"];
    [pFont setFontForView:inviteFriend WithSize:17 WithString:@" INVITE A FRIEND"];
    
    NSInteger winCount = [[GameDataManager sharedInstance] hostWinCount];
    NSString* txtScore = [NSString stringWithFormat:@"WIN %06d", winCount];
    [pFont setFontForView:singlePlayerScore WithSize:12 WithString:txtScore];
    
    winCount = [[GameDataManager sharedInstance] guestWinCount];
    txtScore = [NSString stringWithFormat:@"WIN %06d", winCount];
    [pFont setFontForView:inviteFriendScore WithSize:12 WithString:txtScore];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight
        || interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        return YES;
    
    return NO;
}

#pragma mark - touches

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = [[event allTouches] anyObject];
    
    if (touch.view.tag == 100)
    {
        [self performSegueWithIdentifier:@"SegueToMainViewController" sender:self];
        [[AudioManager sharedInstance] PlaySFX:@"BackSFX"];
    }
}

@end
